dmtlog: Limit strings to 254 characters, until we are know, how to handle them correctly.
authoroliskoli <oliskoli>
Sat, 8 Mar 2008 20:00:53 +0000 (20:00 +0000)
committeroliskoli <oliskoli>
Sat, 8 Mar 2008 20:00:53 +0000 (20:00 +0000)
dmtlog.c

index 502db35ff9d8bddcc09a71835741c0bd29e500c6..0d11cf2cab9b0832cbde3de4885976d63f13ac0e 100644 (file)
--- a/dmtlog.c
+++ b/dmtlog.c
@@ -324,6 +324,26 @@ read_str(gbfile *f)
        return res;
 }
 
+static void
+write_str(const char *str, gbfile *f)
+{
+       if (str && *str) {
+               int len = strlen(str);
+               if (len > 0xfe) {
+#if 0
+                       if (len > 0x7fff) len = 0x7fff;
+                       gbfputc((unsigned char) 0xff, f);
+                       gbfputint16(len, f);
+#else
+                       len = 0xfe;
+                       gbfputc(len, f);
+#endif
+               }
+               else gbfputc(len, f);
+               gbfwrite(str, len, 1, f);
+       }
+       else gbfputc(0, f);
+}
 
 static int
 read_datum(gbfile *f)
@@ -670,18 +690,18 @@ write_header(const route_head *trk)
                queue *curr, *prev;
                QUEUE_FOR_EACH(&trk->waypoint_list, curr, prev) count++;
        }
-       gbfputpstr(trk && trk->rte_name && *trk->rte_name ? trk->rte_name : "Name", fout);
+       write_str(trk && trk->rte_name && *trk->rte_name ? trk->rte_name : "Name", fout);
        
        xasprintf(&cout, "%d trackpoints and %d waypoints", count, waypt_count());
-       gbfputpstr(cout, fout);
+       write_str(cout, fout);
        xfree(cout);
        
        for (i = 3; i <= 8; i++) gbfputc(ZERO, fout);
-       gbfputpstr("GPSBabel", fout);
+       write_str("GPSBabel", fout);
        gbfputint32(count, fout);
        if (count > 0) {
-               gbfputpstr("WGS84", fout);
-               gbfputpstr("WGS84", fout);
+               write_str("WGS84", fout);
+               write_str("WGS84", fout);
        }
 }
 
@@ -721,8 +741,8 @@ wpt_cb(const waypoint *wpt)
        names = 1;
        if (wpt->description && *wpt->description) names = 2;
        gbfputint32(names, fout);
-       if (names > 1) gbfputpstr(wpt->description, fout);
-       gbfputpstr(wpt->shortname && *wpt->shortname ? wpt->shortname : "Name", fout);
+       if (names > 1) write_str(wpt->description, fout);
+       write_str(wpt->shortname && *wpt->shortname ? wpt->shortname : "Name", fout);
 }
 
 static void
@@ -746,8 +766,8 @@ dmtlog_write(void)
                write_header(NULL);
        gbfputint32(waypt_count(), fout);
        if (waypt_count() > 0) {
-               gbfputpstr("WGS84", fout);
-               gbfputpstr("WGS84", fout);
+               write_str("WGS84", fout);
+               write_str("WGS84", fout);
                waypt_disp_all(wpt_cb);
        }
 }